package com.godchicken.praise_each_other.cim.server.kit;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * com.godchicken.praise_each_other.cim.server.kit
 * 2020/11/19
 *
 * @author: godchicken
 *
 * 实现md5加密
 */

public class Md5Kit {
    public static String stringToMD5(String encode){
        byte[] secretBytes = null;
        try {
            MessageDigest md5 = MessageDigest.getInstance("md5");
            secretBytes = md5.digest(encode.getBytes());
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }

        String md5code = new BigInteger(1, secretBytes).toString(16);
        for (int i = 0; i < 32 - md5code.length(); i++) {
            md5code = "0" + md5code;
        }
        return md5code;
    }
}
